<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <el-form-item label="工厂名:" class="myform-item">
          <el-input
            v-model="form.factory_name"
            placeholder="请输入工厂名"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="SKU:" class="myform-item">
          <el-input
            v-model="form.sku_code"
            placeholder="请输入SKU"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="加工单:" class="myform-item">
          <el-input
            v-model="form.processing_code"
            placeholder="请输入加工单"
            @keyup.enter.native="onSearch"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="确认状态:" class="myform-item">
          <el-select v-model="form.m_status" placeholder="请选择" clearable>
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </div>
      <div>
        <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
      </div>
    </el-form>
    <el-table
      :data="tableData"
      style="width: 100%"
      border
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column
        label="成品加工单号"
        align="center"
        prop="processing_code"
      >
      </el-table-column>
      <el-table-column label="状态" align="center" prop="m_status">
        <template slot-scope="{ row }">
          <div :style="{ color: row.m_status != 0 ? '#2c70d6' : '' }">
            {{ row.m_status == 0 ? "未确认" : "已确认" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="工厂" align="center" prop="factory_name">
      </el-table-column>
      <el-table-column label="SKU" align="center" prop="sku_code">
      </el-table-column>
      <el-table-column label="版面" align="center" prop="ban">
      </el-table-column>
      <el-table-column label="面料" align="center" prop="fabric">
        <template slot-scope="{ row }">
          <div v-if="row.lining_one">{{ row.lining_one }}</div>
          <div v-if="row.lining_two">{{ row.lining_two }}</div>
          <div v-if="row.lining_three">{{ row.lining_three }}</div>
          <div v-if="row.lining_four">{{ row.lining_four }}</div>
          <div v-if="row.lining_five">{{ row.lining_five }}</div>
        </template>
      </el-table-column>
      <el-table-column label="款名" align="center" prop="type_name">
      </el-table-column>
      <el-table-column label="理单员" align="center" prop="order_processor">
      </el-table-column>
      <el-table-column label="数量" align="center" prop="num">
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <el-button
            type="text"
            size="default"
            v-if="row.m_status == 0"
            @click="onAffirm(0, row.m_id)"
            >确认</el-button
          >
          <el-button
            type="text"
            size="default"
            style="color: #67c23a"
            v-else
            @click="onPre(row.processing_code)"
            >预览</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-button
      size="default"
      type="primary"
      :disabled="!multipleSelection.length"
      @click="onAffirm(1)"
      style="margin-top: 20px"
      >批量确认</el-button
    >
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postAdminApiCodeGetProcessingMaintainList"
    />
    <el-dialog
      title="水洗唛"
      :visible.sync="dialogVisibleDp"
      width="30%"
      :before-close="handleClose"
    >
      <div style="background: #fff; width: 46mm; height: 131mm">
        <div class="tags" id="tages">
          <div class="tags-one"></div>
          <div class="tags-one1">
            <img :src="logossy" alt="" style="width: 10mm; height: 10mm" />
          </div>
          <div class="tags-one2">SKU：{{ dataDP.type_no }}</div>
          <div class="tags-one3">
            <span style="white-space: pre-wrap" v-html="dataDP.html"></span>
          </div>
          <div style="margin-bottom:3px;font-size: 2.3mm;zoom: 0.73;">洗涤说明:</div>
          <div style="display: flex; justify-content: space-between">
            <img
              v-for="item in dataDP.ximaiimg"
              :key="item"
              :src="item"
              style="width: 20px; height: 20px"
            />
          </div>
          <div class="tags-one4">
            <vue-qr class="qr-code" :text="dataDP.number" :size="110" />
            <div>
              {{ dataDP.number }}
            </div>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleDp = false">取 消</el-button>
        <!-- <el-button type="primary" v-print="'#tages'">打 印</el-button> -->
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  postAdminApiCodeGetProcessingMaintainList,
  postAdminApiCodeSetProcessingMaintainList,
  postAdminCodegetUnprinted,
} from "@/api";
import pagination from "@/components/pagination.vue";
import logossy from "@/assets/images/logossy.png";
import vueQr from "vue-qr";
export default {
  components: { pagination, vueQr },
  data() {
    return {
      loading: false,
      dialogVisible: false,
      dialogVisibleDp: false,
      logossy,
      options: [
        {
          value: 0,
          label: "未确认",
        },
        {
          value: 1,
          label: "已确认",
        },
      ],
      multipleSelection: [],
      form: {
        factory_name: "",
        sku_code: "",
        processing_code: "",
        m_status: "",
        page: 1,
        size: 10,
      },
      dataDP: "",
      tableData: [],
      total: 1,
    };
  },
  activated() {
    let form = this.form;
    this.postAdminApiCodeGetProcessingMaintainList(form);
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 确认
    onAffirm(type, id) {
      let ids = [];
      if (type == 0) {
        ids.push(id);
      } else {
        let multipleSelection = this.multipleSelection;
        multipleSelection.forEach((res) => {
          ids.push(res.m_id);
        });
      }
      let obj = {
        ids,
      };
      this.$confirm("确认加工单面料?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          postAdminApiCodeSetProcessingMaintainList(obj).then((res) => {
            let form = this.form;
            this.postAdminApiCodeGetProcessingMaintainList(form);
            this.$message({
              type: "success",
              message: "确认成功!",
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消确认",
          });
        });
    },
    // 采购列表
    async postAdminApiCodeGetProcessingMaintainList(data) {
      this.loading = true;
      this.form = data;
      postAdminApiCodeGetProcessingMaintainList(data)
        .then((res) => {
          this.loading = false;
          console.log("采购列表", res);
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 预览
    async onPre(processing_code) {
      let data = {
        processing_code,
      };
      let res = await postAdminCodegetUnprinted(data);

      let reg = new RegExp("\r\n", "g");
      let regs = new RegExp("\\\\r\\\\n", "g");
      let dataDP = res.data;
      let fabric = dataDP.fabric;
      console.log("fabric----->");
      let html = fabric.replaceAll(reg, "<br>");
      html = html.replaceAll(regs, "<br>");
      dataDP.html = html;
      this.dataDP = dataDP;
      this.dialogVisibleDp = true;
      console.log("res----->", res);
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postAdminApiCodeGetProcessingMaintainList(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.tags {
  background: #fff;
  width: 45mm;
  height: 110mm;
  border: 1px solid #000;
  // border-radius: 6mm;
  color: #000;
  padding: 0 3mm;
  box-sizing: border-box;

  .tags-one {
    width: 4mm;
    height: 4mm;
    // border-radius: 4mm;
    // border: 0.1mm solid #999;
    height: 11mm;
  }

  .tags-one1 {
    text-align: center;
    margin-top: 30px;
  }

  .tags-one2 {
    font-size: 2.3mm;
    margin-top: 2mm;
    zoom: 0.73;
  }

  .tags-one3 {
    height: 40mm;
    zoom: 0.7;
    font-size: 2mm;
    margin-top: 2mm;
    white-space: pre-line;
  }

  .tags-one4 {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    // margin-top: 16mm;
    > div {
      margin-top: -10px;
      text-align: center;
      width: 90px;
      font-size: 2.3mm;
    }
  }

  .tags-one5 {
    font-size: 2.3mm;
    zoom: 0.7;
    margin-top: 1mm;
  }

  .tags-one6 {
    font-size: 3.6mm;
    font-weight: 600;
    margin-top: 0.8mm;
    margin-left: 2mm;
  }

  .tags-one7 {
    font-size: 2.3mm;
    zoom: 0.73;
    height: 4mm;
    margin-left: 2mm;
  }

  .tags-one8 {
    background: #ffff;
    width: 36mm;
    text-align: center;
    font-size: 2mm;
    margin-top: -2.2mm;

    > span {
      zoom: 0.73;
    }
  }

  .tags-one9 {
    margin-top: 1mm;
    display: flex;

    > img {
      width: 10mm;
      height: 10mm;
    }

    .tags-one9-two {
      margin-left: 2mm;

      > div:nth-child(1) {
        display: flex;
        align-items: center;

        > img {
          width: 4.3mm;
          height: 4.3mm;
          margin-right: 1mm;
        }

        > div {
          font-size: 2.3mm;
          zoom: 0.73;
        }
      }

      > div:nth-child(2) {
        margin-top: 1mm;
        font-size: 2.3mm;
        zoom: 0.48;
      }

      > div:nth-child(3) {
        font-size: 2.3mm;
        zoom: 0.48;
        margin-top: 1mm;
      }
    }
  }
}

.myform {
  display: flex;
  justify-content: space-between;

  > div {
    display: flex;
  }

  &-item {
    margin-right: 10px;
  }
}

.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
